<template>
<div>
  <a-table :pagination="false" :columns="columns" :data-source="data"  v-if="showTable">
      <span slot="url" slot-scope="text, record">
        <img style="width:50px;heigth:50px" :src="record.url" />
      </span>
    <template slot="status" slot-scope="text, record">
      审核中
    </template>
    <template slot="action" slot-scope="text,record">
      <span>
        <a-button type="primary"  icon="form" style="padding-left: 0" @click="doReviewPass(record.id)">通过</a-button>
        <a-divider type="vertical"/>
        <a-button type="primary"  icon="form" @click="doReviewReject(record.id)">拒绝</a-button>
        <a-divider type="vertical"/>
        <a-button type="danger" icon="delete"  danger @click="doDelete(record.id)">删除</a-button>
      </span>
    </template>
  </a-table>
  <h1 v-else style="text-align: center;">暂无数据,喝杯咖啡再来吧!!</h1>
</div>
</template>

<script>
import enums from "@/constant/ EmojiReviewStatusEnum";

export default {
  name: "EmojiAdmin",
  data() {
    return {
      columns: [
        {
          title: 'id',
          dataIndex: 'id',
          key: 'id',
          width: 100,
        },
        {
          title: '名称',
          dataIndex: 'name',
          key: 'name',
          width: 150,
        },
        {
          title: '图片',
          dataIndex: 'url',
          key: 'url',
          width: 150,
          scopedSlots: {customRender: 'url'},
        },
        {
          title: '标签',
          key: 'tags',
          dataIndex: 'tags',
          width: 150
        },
        {
          title: '上传者',
          key: 'userid',
          dataIndex: 'userid',
          width: 150,
        },
        {
          title: '状态',
          key: 'reviewstatus',
          dataIndex: 'reviewstatus',
          width: 100,
          scopedSlots: {customRender: 'status'},
        },
        {
          title: '操作',
          key: 'action',
          fixed: 'right',
          width: 250,
          scopedSlots: {customRender: 'action'},
        },
      ],
      data: [],
      showTable: true,
      status: {
        id: 0,
        reviewStatus: 0
      }
    }
  },
  methods: {
    //查询全部表情
    async getData() {
      this.showTable = true
      const result = await this.$API.findAll(enums.UN_REVIEW)
      if (result.code == 10000) {
        this.data = result.data
      } else
        this.showTable = false
      this.$message.warning('暂无数据!');
    },
    //更新审核状态
    async doReviewPass(index) {
      this.status.id = index
      this.status.reviewStatus = enums.REVIEW_PASS
      let result = await this.$API.updateReviewState(this.status)
      if (result.code == 10000) {
        this.$message.success('更新成功')
        await this.getData()
      } else {
        this.$message.error('更新失败')
      }
    },
    async doReviewReject(index) {
      this.status.id = index
      this.status.reviewStatus = enums.REVIEW_REJECT
      let result = await this.$API.updateReviewState(this.status)
      if (result.code == 10000) {
        this.$message.success('审核拒绝成功')
        await this.getData()
      } else {
        this.$message.error('审核拒绝失败')
      }
    },
    //删除表情
    async doDelete(index) {
      this.status.id = index
      let result = await this.$API.deleteEmoji(this.status)
      if (result.code == 10000) {
        this.$message.success('删除成功')
        await this.getData()
      } else {
        this.$message.error('删除失败')
      }
    },
  },
  mounted() {
    this.getData()
  }
}
</script>

<style scoped>

</style>
